home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Sample Code / Snippets / Development Tools & Languages / AEGestalt / UAEDocument.cp < prev    next >
Encoding:
Text File  |  1995-02-12  |  8.8 KB  |  359 lines  |  [TEXT/MPS ]

  1. //     UAEDocument.cp 
  2. //     Copyright © 1991-92 by Apple Computer, Inc. All rights reserved.
  3. //    Kent Sandvik DTS
  4. //    This file contains the basic TAEDocument member functions
  5. //
  6. //    <1>        khs        1.0        First final version
  7.  
  8.  
  9. // INCLUDES
  10. #ifndef __UAEDOCUMENT__
  11. #include "UAEDocument.h"                                        
  12. #endif
  13.  
  14.  
  15. //    CLASS METHODS 
  16. //    Empty constructor - for avoiding ptabs in global data space
  17.  
  18. #undef Inherited
  19. #define Inherited TDocument
  20.  
  21. #pragma segment ARes
  22. DefineClass(TAEDocument, TDocument);
  23.  
  24. TAEDocument::TAEDocument()
  25. {
  26. }
  27.  
  28. //    Create TAEDocument
  29. #pragma segment AInit
  30. void TAEDocument::IAEDocument()
  31. {
  32.     Inherited::IDocument();
  33.     
  34.     // initialize handle to AE
  35.     fAEGestaltAddress.descriptorType = typeNull;
  36.     fAEGestaltAddress.dataHandle = NULL;
  37.     fConfigurationInfo = NULL;
  38.     fOKNode = FALSE;
  39. }
  40.  
  41.  
  42. //    Create any needed TDocument Views
  43. #pragma segment AOpen
  44. void TAEDocument::DoMakeViews(Boolean    /*forPrinting*/)
  45. {
  46.     TWindow * aWindow = NULL;
  47.     FailInfo fi;
  48.     
  49.     Try(fi)
  50.     {
  51.         // create Main Information Window    
  52.         aWindow = (TWindow *)gViewServer->NewTemplateWindow(kMainWindow, this);
  53.  
  54.         // find text views
  55.         fInfoField = (TStaticText *)aWindow->FindSubView('info');
  56.         fLabelView = (TLabelView *)aWindow->FindSubView('VIW1');
  57.         fInfoView    = (TInformationView *)aWindow->FindSubView('VIW2');
  58.  
  59.         // find buttons
  60.         fFindButton = (TButton *)aWindow->FindSubView('find');
  61.         fReportButton = (TButton *)aWindow->FindSubView('repo');
  62.  
  63.  
  64. //    Add Adorners to various views - yes this would be far better to do
  65. //    from the resource file itself, but as long as there's no ViewEdit 3.0
  66. //    which handles the new format, I'm hesitant to hack in by hand these
  67. //    values, because it's a tidy exersize.
  68.  
  69.         // add window adorners, fill gray background
  70.         aWindow->AddAdorner(NewStdAdorner('gray',"",'gray', kFreeOnDeletion), 
  71.                                             kAdornBefore, kRedraw);
  72.                                             
  73.         // add view adorners, frame second view
  74.         fInfoView->AddAdorner(NewStdAdorner('fram', "", 'fram', kFreeOnDeletion),
  75.                                             kDrawView, kRedraw);
  76.         fInfoView->AddAdorner(NewStdAdorner('eras', "", 'eras', kFreeOnDeletion),
  77.                                             kDrawView, kRedraw);
  78.         
  79.         // add static text adorner, erase background
  80.         fInfoField->AddAdorner(NewStdAdorner('eras', "", 'eras', kFreeOnDeletion),
  81.                                                 kDrawView, kRedraw);
  82.         fi.Success();
  83.     }
  84.     else
  85.         fi.ReSignal();
  86. }
  87.  
  88.  
  89. //    Handle Events passed to TDocument, like the find button event
  90. #pragma segment AMain
  91. void TAEDocument::DoEvent(EventNumber eventNumber,
  92.                                  TEventHandler* source,
  93.                                  TEvent* event)
  94. {
  95.     if (eventNumber == mButtonHit)
  96.     {
  97.         // were any of the buttons pressed?
  98.         if (source->fIdentifier == 'find')
  99.         {
  100.             // find button?    
  101.             // post a menu command which translates to the Find… menu entry    
  102.             this->HandleMenuCommand(cFindAEGestalt);
  103.         }
  104.  
  105.         else if (source->fIdentifier == 'repo')
  106.         {
  107.             // report button & we have valid node?
  108.             if (fOKNode)
  109.             // post a menu command which translates to the Report… menu entry    
  110.                 this->HandleMenuCommand(cCreateReport);
  111.         }
  112.     }
  113.     else
  114.         Inherited::DoEvent(eventNumber, source, event);
  115. }
  116.  
  117.  
  118. //    Free any resources attached to the TDocument, take also care of AE resources
  119. #pragma segment AClose
  120. void TAEDocument::Free()
  121. {
  122.     AEAddressDesc aDesc = fAEGestaltAddress;
  123.     // dispose the descriptor!
  124.     AEDisposeDesc(&aDesc);
  125.  
  126.     Inherited::Free();
  127. }
  128.  
  129.  
  130. //    Setup menus when TDocument is created
  131. #pragma segment ARes
  132. void TAEDocument::DoSetupMenus()
  133. {
  134.     Inherited::DoSetupMenus();
  135.  
  136.     // we assume that we are starting from a Find command
  137.     Enable(cFindAEGestalt, TRUE);
  138.  
  139.     // we can't report anything until we have information
  140.     Enable(cCreateReport, fAEGestaltAddress.dataHandle != NULL);
  141.     fReportButton->DimState(!(fAEGestaltAddress.dataHandle != NULL), TRUE);
  142. }
  143.  
  144.  
  145. //    Handle menu commands assigned to the TDocument controlled menus
  146. #pragma segment ASelCommand
  147. void TAEDocument::DoMenuCommand(CommandNumber theNumber)
  148. {
  149.     TCommand * cmdToPost = NULL;
  150.     TAEClientCommand * AEcmd = NULL;
  151.     TLookupCommand * aLookup = NULL;
  152.  
  153.  
  154.     switch (theNumber)
  155.     {
  156.         case cFindAEGestalt:
  157.             aLookup = new TLookupCommand;
  158.             aLookup->ILookupCommand(cFindAEGestalt, this);
  159.             cmdToPost = aLookup;
  160.             fInfoField->SetText("Look for node to examine...", TRUE);
  161.             break;
  162.  
  163.         case cCreateReport:
  164.             AEcmd = new TAEClientCommand;
  165.             AEcmd->IAEClientCommand(cCreateReport, this, kAEGetConfig);
  166.             cmdToPost = AEcmd;
  167.             fInfoField->SetText("Report node information...", TRUE);
  168.             break;
  169.  
  170.         default:
  171.             Inherited::DoMenuCommand(theNumber);
  172.     }
  173.     if (cmdToPost != NULL)
  174.         this->PostAnEvent(cmdToPost);
  175. }
  176.  
  177.  
  178. //    Return the AppleEvents address stored in TAEDocument
  179. #pragma segment ARes
  180. void TAEDocument::GetAEGestaltAddress(AEAddressDesc& theAddress)
  181. {
  182.     theAddress = fAEGestaltAddress;
  183. }
  184.  
  185.  
  186. //    Read the Configuration information
  187. #pragma segment Main
  188. void TAEDocument::ReadConfiguration(Configuration* theConfig)
  189. {
  190.     BlockMove(&theConfig, &fConfigurationInfo, sizeof(theConfig));
  191. }
  192.  
  193.  
  194. //    Process the information we got from the AE for the View class for
  195. //    later display
  196. #pragma segment Main
  197. void TAEDocument::ProcessAEInformation()
  198. {
  199.     switch (fConfigurationInfo->machineType)
  200.     {                                            // Label1 - Machine Type
  201.         case 1:
  202.             fInfoView->fLabel1 = "Classic";
  203.             break;
  204.         case 2:
  205.             fInfoView->fLabel1 = "MacXL";
  206.             break;
  207.         case 3:
  208.             fInfoView->fLabel1 = "Mac512KE";
  209.             break;
  210.         case 4:
  211.             fInfoView->fLabel1 = "Mac Plus";
  212.             break;
  213.         case 5:
  214.             fInfoView->fLabel1 = "MacSE";
  215.             break;
  216.         case 6:
  217.             fInfoView->fLabel1 = "MacII";
  218.             break;
  219.         case 7:
  220.             fInfoView->fLabel1 = "MacIIx";
  221.             break;
  222.         case 8:
  223.             fInfoView->fLabel1 = "MacIIcx";
  224.             break;
  225.         case 9:
  226.             fInfoView->fLabel1 = "MacSe030";
  227.             break;
  228.         case 10:
  229.             fInfoView->fLabel1 = "Portable";
  230.             break;
  231.         case 11:
  232.             fInfoView->fLabel1 = "MacIIci";
  233.             break;
  234.         case 13:
  235.             fInfoView->fLabel1 = "MacIIfx";
  236.             break;
  237.         case 17:
  238.             fInfoView->fLabel1 = "Mac Classic";
  239.             break;
  240.         case 18:
  241.             fInfoView->fLabel1 = "MacIIsi";
  242.             break;
  243.         case 19:
  244.             fInfoView->fLabel1 = "MacLC";
  245.             break;
  246.         case 20:
  247.             fInfoView->fLabel1 = "Quadra 900";
  248.             break;
  249.         case 21:
  250.             fInfoView->fLabel1 = "PowerBook 140";
  251.             break;
  252.         case 22:
  253.             fInfoView->fLabel1 = "Quadra 700";
  254.             break;
  255.         case 23:
  256.             fInfoView->fLabel1 = "Classic II";
  257.             break;
  258.         case 24:
  259.             fInfoView->fLabel1 = "PowerBook 100";
  260.             break;
  261.         case 25:
  262.             fInfoView->fLabel1 = "PowerBook 140";
  263.             break;
  264.         default:
  265.             fInfoView->fLabel1 = "Unknown type";
  266.             break;
  267.     }
  268.  
  269.     if (fConfigurationInfo->systemVersion == 0x700)// Label2 - System Version
  270.         fInfoView->fLabel2 = "System 7.0";
  271.     else if (fConfigurationInfo->systemVersion == 0x701)
  272.         fInfoView->fLabel2 = "System 7.0.1";
  273.     else if (fConfigurationInfo->systemVersion == 0x602)
  274.         fInfoView->fLabel2 = "System 6.0.2";
  275.     else if (fConfigurationInfo->systemVersion == 0x603)
  276.         fInfoView->fLabel2 = "System 6.0.3";
  277.     else if (fConfigurationInfo->systemVersion == 0x604)
  278.         fInfoView->fLabel2 = "System 6.0.4";
  279.     else if (fConfigurationInfo->systemVersion == 0x605)
  280.         fInfoView->fLabel2 = "System 6.0.5";
  281.     else if (fConfigurationInfo->systemVersion == 0x607)
  282.         fInfoView->fLabel2 = "System 6.0.7";
  283.     else if (fConfigurationInfo->systemVersion < 0x600)
  284.         fInfoView->fLabel2 = "Pre 6.0.x System";
  285.     else if (fConfigurationInfo->systemVersion > 0x701)
  286.         fInfoView->fLabel2 = "Post 7.0.1 System";
  287.  
  288.     switch (fConfigurationInfo->processor)
  289.     {                                            // Label3 - Processor Type
  290.         case 1:
  291.             fInfoView->fLabel3 = "68000";
  292.             break;
  293.         case 2:
  294.             fInfoView->fLabel3 = "68010";
  295.             break;
  296.         case 3:
  297.             fInfoView->fLabel3 = "68020";
  298.             break;
  299.         case 4:
  300.             fInfoView->fLabel3 = "68030";
  301.             break;
  302.         case 5:
  303.             fInfoView->fLabel3 = "68040";
  304.             break;
  305.         default:
  306.             fInfoView->fLabel3 = "Unknown CPU";
  307.             break;
  308.     }
  309.  
  310.     if (fConfigurationInfo->hasFPU)                // Label4 - Has FPU?
  311.         fInfoView->fLabel4 = "TRUE";
  312.     else
  313.         fInfoView->fLabel4 = "FALSE";
  314.  
  315.     if (fConfigurationInfo->hasColorQD)            // Label5 - Has Color QD?
  316.         fInfoView->fLabel5 = "TRUE";
  317.     else
  318.         fInfoView->fLabel5 = "FALSE";
  319.  
  320.     if (fConfigurationInfo->has32BitQD)            // Label6 - Has 32-bit QD?
  321.         fInfoView->fLabel6 = "TRUE";
  322.     else
  323.         fInfoView->fLabel6 = "FALSE";
  324.  
  325.     if (fConfigurationInfo->hasSCSI)            // Label7 - Has SCSI?
  326.         fInfoView->fLabel7 = "TRUE";
  327.     else
  328.         fInfoView->fLabel7 = "FALSE";
  329.  
  330.     if (fConfigurationInfo->hasAppleEventMgr)    // Label8 - Has AppleEvent Mgr?
  331.         fInfoView->fLabel8 = "TRUE";
  332.     else
  333.         fInfoView->fLabel8 = "FALSE";
  334.  
  335.     if (fConfigurationInfo->hasEditionMgr)        // Label9 - Has Edition Mgr?
  336.         fInfoView->fLabel9 = "TRUE";
  337.     else
  338.         fInfoView->fLabel9 = "FALSE";
  339.  
  340.     if (fConfigurationInfo->hasAUX)                // Label10 - Is A/UX System?
  341.         fInfoView->fLabel10 = "TRUE";
  342.     else
  343.         fInfoView->fLabel10 = "FALSE";
  344.  
  345.     if (fConfigurationInfo->hasTrueType)        // Label11 - Has TrueType?
  346.         fInfoView->fLabel11 = "TRUE";
  347.     else
  348.         fInfoView->fLabel11 = "FALSE";
  349.  
  350.     CStr255 tempString;                            // Label12 - AppleTalk version
  351.     NumToString(long(fConfigurationInfo-> atDrvrVersNum), tempString);
  352.     fInfoView->fLabel12 = tempString;
  353.  
  354.     fInfoView->fHasGestaltInfo = TRUE;            // report for view to draw
  355.     fInfoView->ForceRedraw();                    // redraw the view
  356. }
  357.  
  358.  
  359.